package com.hui.blog_server.controller;

import com.hui.blog_server.entity.ResponseResult;
import com.hui.blog_server.entity.User;
import com.hui.blog_server.entity.Userinfo;
import com.hui.blog_server.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 彩色的小灰
 */
@RestController
public class UserController {

    @Autowired
    private UserServiceImpl userService;

    @PostMapping("/login")
    public ResponseResult<?> login(@RequestBody User user) {
        Userinfo loginRes = userService.login(user.getEmail(), user.getPassword());
        if (loginRes != null) {
            return ResponseResult.success(loginRes);
        }
        else {
            return ResponseResult.fail();
        }
    }
}
